<?php
/* [DoYouHaoBaby!] (C)Dianniu From 2010.
   this($)*/

!defined('DYHB_PATH') && exit;

class TemplateGtkGladeWidgetCompiler_GtkTable extends TemplateGtkGladeWidgetCompilerBase{

	protected function compileCreateWidget_(TemplateGtkGladeWidget $oObject){
		$sWidgetClass=$oObject->getWidgetClass();
		$sVariableName='$'.TemplateGtkGlade::getWidgetVariableName($oObject);
		$nRows=(int)$oObject->getProperty('n_rows');// 行、列
		$nColumns=(int)$oObject->getProperty('n_columns');
		$sHomogeneous= TemplateGtkGladeObj::nodeTextToValue($oObject->getProperty('homogeneous'))? 'true': 'false';// 统一大小
		$sCompiled="\t\t{$sVariableName}=new {$sWidgetClass}({$nRows}, {$nColumns}, {$sHomogeneous});";
		if($sRowSpacing=$oObject->getProperty('row_spacing')){$sCompiled.= "\t\t{$sVariableName}->set_row_spacings({$sRowSpacing});";}// 间隔
		if($sClmSpacing=$oObject->getProperty('column_spacing')){$sCompiled.= "\t\t{$sVariableName}->set_col_spacings({$sClmSpacing});";}
		return $sCompiled;
	}

	protected function compileChildWidgetPacking_(TemplateGtkGladeWidget $oParentWidget,TemplateGtkGladeWidget $oChildWidget, TemplateGtkGladeWidgetPacking $oPacking){
		$sParentVariableName='$'.TemplateGtkGlade::getWidgetVariableName($oParentWidget);// 父/子 窗体变量名
		$sChildWidgetVariableName='$'.TemplateGtkGlade::getWidgetVariableName($oChildWidget);
		$sChildWidgetId=$oChildWidget->getWidgetId();
		if(($sLeftAttach=$oPacking->getProperty('left_attach'))===null){$sLeftAttach='0';}// 上下左右 位置
		if(($sRightAttach=$oPacking->getProperty('right_attach'))===null){$sRightAttach='1';}
		if(($sTopAttach=$oPacking->getProperty('top_attach'))===null){$sTopAttach='0';}
		if(($sBottomAttach=$oPacking->getProperty('bottom_attach'))===null){$sBottomAttach='1';}
		if(($sXOptions=$oPacking->getProperty('x_options'))===null){$sXOptions='GTK_EXPAND | GTK_FILL';}// x/y options
		if($sXOptions===''){$sXOptions='0';}
		if(($sYOptions=$oPacking->getProperty('y_options'))===null){$sYOptions='GTK_EXPAND | GTK_FILL';}
		if($sYOptions===''){$sYOptions='0';}
		$sXOptions=str_replace('GTK_','Gtk::',$sXOptions);
		$sYOptions=str_replace('GTK_','Gtk::',$sYOptions);
		if(($sXPadding=$oPacking->getProperty('x_padding'))===null){$sXPadding='0';}// x/y padding
		if(($sYPadding=$oPacking->getProperty('y_padding'))===null){$sYPadding='1';}
		$sCompiled="\t\t{$sChildWidgetVariableName}=\$this->getWidget('{$sChildWidgetId}',\$arrObjectForSignal);";
		$sCompiled.="\t\t{$sParentVariableName}->attach({$sChildWidgetVariableName}, {$sLeftAttach},{$sRightAttach},{$sTopAttach},{$sBottomAttach}, {$sXOptions},{$sYOptions}, {$sXPadding},{$sYPadding});";
		return $sCompiled;
	}

	static public function regToProcessorManager(ITemplateObjProcessorManager $oManager){
		$oManager->regProcessor(str_replace('TemplateGtkGladeWidgetCompiler_','',__CLASS__),__CLASS__);
	}

}
